package D240527.Practice;

import java.util.ArrayList;

public class Student {
    private final String name;
    private final int age;
    private final String hometown;
    private final char firstLetter;
    private static ArrayList<Student> students = new ArrayList<>();

    public Student(String name, char firstLetter, int age, String hometown) {
        this.name = name;
        this.firstLetter = firstLetter;
        this.age = age;
        this.hometown = hometown;
        students.add(this);
    }

    public static void showAll() {
        for (int i = 0; i < students.size(); i++) {
            System.out.println(students.get(i));
        }
    }

    public static void showByName(String name) {
        for (int i = 0; i < students.size(); i++) {
            if (name.equals(students.get(i).name)) {
                System.out.println(students.get(i));
            }
        }
    }

    public static void showByAge(int age) {
        for (int i = 0; i < students.size(); i++) {
            if (age == students.get(i).age) {
                System.out.println(students.get(i));
            }
        }
    }

    public static void showByHometown(String hometown) {
        for (int i = 0; i < students.size(); i++) {
            if (hometown.equals(students.get(i).hometown)) {
                System.out.println(students.get(i));
            }
        }
    }
    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", hometown='" + hometown + '\'' +
                '}';
    }


}
